/**
 * 
 */
package com.qhgrain.app.service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.paas.base.modules.utils.net.http.HttpUtil;
import com.qhgrain.app.constant.UrlEnum;
import com.qhgrain.app.util.ConfigUtil;

/**
 * 代理4A或封装IAM接口服务层
 * @author Administrator
 *
 */
@Service
public class AgentService {
	
	private static Logger LOG = LoggerFactory.getLogger(AgentService.class);
	
	private final static String IAM_URL = ConfigUtil.getProperties(UrlEnum.IAM);
	
	/**
	 * 
	 * 获取直属单位
	 * @param 
	 * @return 
	 * @author Administrator
	 * @date 2016年6月14日
	 */
	public String getDirectUnitByUuid(String uuid) throws Exception{
	    String condition="{\"and\":[{\"eq\":{\"keyMappingField03\":\"0\"}}]}";
	    String url=IAM_URL+"/iam/v1/depts/queryDeptsByParentUuid/1/"+uuid;
	    Map map=new HashMap();
	    map.put("condition",condition);
	    return HttpUtil.post(url,map);
	}
	
	/**
     * 
     * 获取涉粮企业
     * @param 
     * @return 
     * @author Administrator
     * @date 2016年6月14日
     */
    public String getGrainUnitByUuid(String uuid) throws Exception{
        String condition="{\"and\":[{\"eq\":{\"keyMappingField01\":\"0\"}}]}";
        String url=IAM_URL+"/iam/v1/depts/queryDeptsByParentUuid/1/"+uuid;
        Map map=new HashMap();
        map.put("condition",condition);
        return HttpUtil.post(url,map);
    }
    
    public String changeUserPassword(String userName, String oldPassword, String newPassword) throws IOException{
    	String url = IAM_URL+"/iam/v1/users/"+userName+"/changePassword";
    	Map<String,Object> map = new HashMap<String,Object>();
    	map.put("userName", userName);
    	map.put("oldPassword", oldPassword);
    	map.put("newPassword", newPassword);
    	return HttpUtil.post(url, map);
    	
    }
	
}
